import org.apache.spark
import org.apache.spark.sql.SparkSession

object traffic_detect_ordercar {



  object MonitorCarNumSort{
    def concatMC(tupple:(org.apache.spark.sql.Row)) = {
      val monitorId:Any = tupple.get(1)
      val cameraId:Any = tupple.get(2)
      val carlicensePlate:Any = tupple.get(3)
      (monitorId,cameraId+"-"+carlicensePlate)
    }
  }

  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder().appName("traffic_detection").getOrCreate()

    spark.sql("use traffic")
    val flow_rdd = spark.sql("select * from monitor_flow_action").rdd

    val flow_rdd_MonitorCarNumSort_tupple = flow_rdd.map(MonitorCarNumSort.concatMC).distinct()
    flow_rdd_MonitorCarNumSort_tupple.map(key=>{(key._1,1)}).reduceByKey(_+_).map(key=>{(key._2,key._1)})
      .sortByKey(false).take(100).foreach(println)

  }
  //



}
